package main

import (
	"flag"
	"fmt"
	"fox/config"
	"fox/db"
	"fox/models"
	"os"
)

var (
	confFile string
)

func initArgs() {
	var (
		currentDir string
		path       string
	)
	currentDir, _ = os.Getwd()
	path = currentDir + "/config/config.json"
	flag.StringVar(&confFile, "config", path, "指定config.json")
	flag.Parse()
}

func main() {
	var (
		err error
	)

	initArgs()

	if err = config.InitConfig(confFile); err != nil {
		fmt.Println("加载配置文件错误:", err)
		panic(err)
	}

	//初始化数据库
	if err = db.InitDB(); err != nil {
		fmt.Println("加载数据库错误:", err)
		panic(err)
	}

	if err = db.GDatabase.Db.AutoMigrate(
		&models.User{},
		&models.Role{},
		&models.Permission{},
		&models.UserRole{},
		&models.RolePermission{}); err != nil {
		fmt.Println("migrate错误:", err)
		panic(err)
	}

	fmt.Println("migrate完成")

}
